<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Validator;

class UserRegisterRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'username' => 'required|between:4,16|unique:users',
            'password' => 'required|alpha_dash|between:6,16|confirmed',
            'password_confirmation' => 'required',
            'department' => 'required',
            'area' => 'required',
            'address' => 'required',
            'name' => 'required',
            'mobile' => 'required',
            'frontend_card' => 'required',
            'backend_card' => 'required',
            'license' => 'required',
        ];
    }

    /**
     * 获取验证错误的自定义属性
     *
     * @return array
     */
    public function attributes()
    {
        return [
            "username"=>"账号","password"=>"密码","confirm_password"=>"确认密码","department"=>"单位名称",
            "area"=>"所在地区","address"=>"单位地址","name"=>"法人名称","mobile"=>"法人电话",
            "frontend_card"=>"身份证正面照","backend_card"=>"身份证背面照","license"=>"营业执照"
        ];
    }

    /**
     * 获取已定义验证规则的错误消息。
     *
     * @return array
     */
    public function messages()
    {
        return [
            'required' => ':attribute不能为空!',
            'username.between' => ':attribute长度为4-16字符!',
            'username.unique' => '此:attribute已存在!',
            'password.alpha_dash' => ':attribute包含字母、数字，短破折号（-）和下划线（_）!',
            'password.between' =>  ':attribute长度为6-16字符!',
            'password.confirmed' =>  ':attribute与确认密码不一致!',
        ];
    }

}
